package org.example.lanhang.controller;

import org.example.lanhang.TbSVO.TbSVO;
import org.example.lanhang.entity.TbSpecification;
import org.example.lanhang.service.tb_specificationService;
import org.example.lanhang.util.PageResult;
import org.example.lanhang.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/TbSpecification")
@CrossOrigin
public class tb_specificationController {
    @Autowired
    private tb_specificationService tbSpecificationService;

    @GetMapping("/list")
    public List<TbSpecification> findall() {
        return tbSpecificationService.findall();
    }

    //2. 分页查询信息
    @GetMapping("/findByPage")
    public PageResult<TbSpecification> findByPage(@RequestParam("page") Integer page,
                                                  @RequestParam("pageSize") Integer pageSize) {
        return tbSpecificationService.findByPage(page, pageSize);
    }

    @PostMapping("/search")
    public PageResult<TbSpecification> search(@RequestParam("page") Integer page,
                                              @RequestParam("pageSize") Integer pageSize,
                                              @RequestBody(required = false) TbSVO tbSVO) {
        return tbSpecificationService.search(page, pageSize, tbSVO);
    }

    @PostMapping("/save")
    public R save(@RequestBody TbSpecification tbSpecification){
        return tbSpecificationService.save(tbSpecification)?R.ok().message("保存成功"):R.error().message("保存失败");
    }
}
